package com.mall.config;

import com.alibaba.druid.pool.DruidDataSource;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@ConfigurationProperties(prefix = "spring.datasource")
@Data
@Component("druidDataSource")
public class DataSourceProperties {
    private String driverClassName;
    private String url;
    private String username;
    private String password;

    @Bean
    public  DruidDataSource dataSource() {
        System.out.println(System.getProperty("user.dir"));
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setUrl(url);
        druidDataSource.setDriverClassName(driverClassName);
        druidDataSource.setUsername(username);
        druidDataSource.setPassword(password);
        return druidDataSource;
    }
}
